/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import BUSServices.NhaXuatBan;
import BUSServices.Sach;
import BUSServices.TheLoai;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.InternalFrameFocusTraversalPolicy;

/**
 *
 * @author Admin
 */
public class SachThongThuong extends javax.swing.JDialog {

    BUSServices.QLNSBUSWebService_Service service;
    BUSServices.QLNSBUSWebService port;
    private DefaultComboBoxModel cbModelTheLoai;
    private DefaultComboBoxModel cbModelNXB;

    public SachThongThuong(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        this.cbModelNXB = new DefaultComboBoxModel();
        this.cbModelTheLoai = new DefaultComboBoxModel();
        //Khởi tạo services và gọi services.
        service = new BUSServices.QLNSBUSWebService_Service();
        port = service.getQLNSBUSWebServicePort();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jbtnHuy = new javax.swing.JButton();
        jbtnNhap = new javax.swing.JButton();
        jtfSoLuong = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfMaSach = new javax.swing.JTextField();
        jcbTheLoai = new javax.swing.JComboBox();
        jcbNhaXB = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jtfGiaBan = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jbnHinhBia = new javax.swing.JButton();
        jbtnHinhChiTiet = new javax.swing.JButton();
        jtfHinhBia = new javax.swing.JTextField();
        jtfHinhChiTiet = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jbtnThoat = new javax.swing.JButton();
        jtfTenSach = new javax.swing.JTextField();
        jtfTacGia = new javax.swing.JTextField();
        jtfNgayNhap = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jbtnTraCuu = new javax.swing.JButton();

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Nhập sách thường");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Tên Sách:");

        jbtnHuy.setText("Hủy");
        jbtnHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnHuyActionPerformed(evt);
            }
        });

        jbtnNhap.setText("Nhập");
        jbtnNhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNhapActionPerformed(evt);
            }
        });
        jbtnNhap.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jbtnNhapKeyReleased(evt);
            }
        });

        jtfSoLuong.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfSoLuongKeyPressed(evt);
            }
        });

        jLabel4.setText("Tác Giả:");

        jLabel5.setText("Số Lượng:");

        jLabel6.setText("Thể Loại:");

        jLabel7.setText("Mã sách:");

        jtfMaSach.setEnabled(false);

        jcbTheLoai.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Truyện ngắn", "Tiểu thuyết", "Truyện tranh" }));

        jcbNhaXB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Giáo Dục", "Trẻ", " " }));

        jLabel10.setText("Giá bán:");

        jtfGiaBan.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfGiaBanKeyPressed(evt);
            }
        });

        jLabel3.setText("Ngày nhập:");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn đường đẫn hình sách"));

        jbnHinhBia.setText("Hình bìa");
        jbnHinhBia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbnHinhBiaActionPerformed(evt);
            }
        });
        jbnHinhBia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbnHinhBiaKeyPressed(evt);
            }
        });

        jbtnHinhChiTiet.setText("Hình chi tiết");
        jbtnHinhChiTiet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnHinhChiTietActionPerformed(evt);
            }
        });
        jbtnHinhChiTiet.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtnHinhChiTietKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtnHinhChiTiet)
                    .addComponent(jbnHinhBia))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfHinhBia)
                    .addComponent(jtfHinhChiTiet, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbnHinhBia, jbtnHinhChiTiet});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbnHinhBia)
                    .addComponent(jtfHinhBia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnHinhChiTiet)
                    .addComponent(jtfHinhChiTiet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setText("Nhà xuất bản:");

        jbtnThoat.setText("Thoát");
        jbtnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThoatActionPerformed(evt);
            }
        });

        jtfTenSach.setDragEnabled(true);
        jtfTenSach.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfTenSachKeyPressed(evt);
            }
        });

        jtfTacGia.setDragEnabled(true);
        jtfTacGia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfTacGiaKeyPressed(evt);
            }
        });

        jtfNgayNhap.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfNgayNhapKeyPressed(evt);
            }
        });

        jLabel8.setText("(yyyy-mm-dd)");

        jbtnTraCuu.setText("Tra cứu sách");
        jbtnTraCuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnTraCuuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcbTheLoai, 0, 119, Short.MAX_VALUE)
                            .addComponent(jtfMaSach))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jLabel1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jbtnTraCuu, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jbtnHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jbtnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(39, 39, 39)
                                .addComponent(jtfNgayNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel10)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jtfGiaBan, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(26, 26, 26)
                                    .addComponent(jcbNhaXB, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jtfSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel8)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jtfTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jtfTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jtfMaSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jcbTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jcbNhaXB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(jLabel4))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtfGiaBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel10))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfNgayNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnNhap, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnTraCuu, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jcbNhaXB, jcbTheLoai, jtfGiaBan, jtfMaSach, jtfNgayNhap, jtfSoLuong});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jtfTacGia, jtfTenSach});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        //Load mã sách tự động
        String mySQL = "SELECT * FROM sach ORDER BY ma_sach DESC LIMIT 1";
        List<Sach> sachs = port.laySach(mySQL);
        int maSach = sachs.get(0).getMaSach();
        int maSachMoi = maSach + 1;
        jtfMaSach.setText(String.valueOf(maSachMoi));

        //Load thể loại
        List<TheLoai> theLoais = port.layTheLoai("SELECT * FROM the_loai");
        for (TheLoai theLoai : theLoais) {
            Vector vt = new Vector();
            vt.add(theLoai.getMaTheLoai());
            vt.add(theLoai.getTenTheLoai());
            this.cbModelTheLoai.addElement(vt);
        }
        this.jcbTheLoai.setModel(cbModelTheLoai);


        //Load nhà xuất bản
        List<NhaXuatBan> nxbs = port.layNhaxuatBan("SELECT * FROM nha_xuat_ban");
        for (NhaXuatBan nhaXuatBan : nxbs) {
            Vector vt = new Vector();
            vt.add(nhaXuatBan.getMaNXB());
            vt.add(nhaXuatBan.getTenNXB());
            this.cbModelNXB.addElement(vt);
        }
        this.jcbNhaXB.setModel(cbModelNXB);

    }//GEN-LAST:event_formWindowOpened

    private void jbnHinhBiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbnHinhBiaActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Chọn hình bìa cho sách");
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();

        this.jtfHinhBia.setText("image/" + f.getName());
        this.jbtnHinhChiTiet.requestFocus();


    }//GEN-LAST:event_jbnHinhBiaActionPerformed

    private void jbtnHinhChiTietActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHinhChiTietActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Chọn hình chi tiết cho sách");
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();

        this.jtfHinhChiTiet.setText("image/" + f.getName());

        this.jbtnNhap.requestFocus();
        this.jbtnNhap.setBackground(Color.red);
    }//GEN-LAST:event_jbtnHinhChiTietActionPerformed

    //Lưu sách vào cơ sở dữ liệu
    private void jbtnNhapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNhapActionPerformed
        try {
            Sach s = new Sach();
            s.setMaSach(Integer.parseInt(this.jtfMaSach.getText()));
            s.setTenSach(this.jtfTenSach.getText());
            s.setTacGia(this.jtfTacGia.getText());
            s.setSoLuongTon(Integer.parseInt(this.jtfSoLuong.getText()));
            s.setSoLuongBan(0);
            s.setTinhTrang(1);
            s.setHinhBia(this.jtfHinhBia.getText());
            s.setHinhChiTiet(this.jtfHinhChiTiet.getText());
            s.setGiaBan(Float.parseFloat(this.jtfGiaBan.getText()));
            s.setNgayNhap(this.jtfNgayNhap.getText());
            Vector vt = (Vector) this.jcbTheLoai.getSelectedItem();
            int maTheLoai = (Integer) vt.get(0);
            s.setMaTheLoai(maTheLoai);
            vt = (Vector) this.jcbNhaXB.getSelectedItem();
            int maNXB = (Integer) vt.get(0);
            s.setMaNhaXuatBan(maNXB);
            s.setMaLoaiSach(1);

            boolean kq = port.themSach(s);
            if (kq == true) {
                JOptionPane.showMessageDialog(this, "Thêm thành công");
            } else {
                JOptionPane.showMessageDialog(this, "Thêm thất bại");
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }

    }//GEN-LAST:event_jbtnNhapActionPerformed

    private void jbtnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThoatActionPerformed
        this.dispose();
    }//GEN-LAST:event_jbtnThoatActionPerformed

    private void jtfTenSachKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfTenSachKeyPressed
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.jtfTenSach.transferFocus();
        }
    }//GEN-LAST:event_jtfTenSachKeyPressed

    private void jtfGiaBanKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfGiaBanKeyPressed
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.jtfGiaBan.transferFocus();
        }
    }//GEN-LAST:event_jtfGiaBanKeyPressed

    private void jtfSoLuongKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfSoLuongKeyPressed
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.jtfSoLuong.transferFocus();
        }
    }//GEN-LAST:event_jtfSoLuongKeyPressed

    private void jtfTacGiaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfTacGiaKeyPressed
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.jtfTacGia.transferFocus();
        }
    }//GEN-LAST:event_jtfTacGiaKeyPressed

    private void jtfNgayNhapKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfNgayNhapKeyPressed
         int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            this.jbnHinhBia.requestFocus();
        }
    }//GEN-LAST:event_jtfNgayNhapKeyPressed

    private void jbnHinhBiaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbnHinhBiaKeyPressed
         int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            jbnHinhBiaActionPerformed(null);
            
        }
    }//GEN-LAST:event_jbnHinhBiaKeyPressed

    private void jbtnHinhChiTietKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtnHinhChiTietKeyPressed
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            jbtnHinhChiTietActionPerformed(null);
        }
    }//GEN-LAST:event_jbtnHinhChiTietKeyPressed

    private void jbtnNhapKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtnNhapKeyReleased
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            jbtnNhapActionPerformed(null);
        }
    }//GEN-LAST:event_jbtnNhapKeyReleased

    private void jbtnHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHuyActionPerformed
       /*
        Component[] component = this.getComponents();
        for (Component item : component) {
            if(item instanceof JTextField){
                JTextField temp = (JTextField)item;
                temp.setText("");
            }
        }
        */
        
    }//GEN-LAST:event_jbtnHuyActionPerformed

    private void jbtnTraCuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnTraCuuActionPerformed
       
        TimSach t = new TimSach(this);
        t.setTitle("Tra cứu thông tin sách");
        t.setVisible(true);
    }//GEN-LAST:event_jbtnTraCuuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SachThongThuong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SachThongThuong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SachThongThuong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SachThongThuong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SachThongThuong dialog = new SachThongThuong(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JButton jbnHinhBia;
    private javax.swing.JButton jbtnHinhChiTiet;
    private javax.swing.JButton jbtnHuy;
    private javax.swing.JButton jbtnNhap;
    private javax.swing.JButton jbtnThoat;
    private javax.swing.JButton jbtnTraCuu;
    private javax.swing.JComboBox jcbNhaXB;
    private javax.swing.JComboBox jcbTheLoai;
    private javax.swing.JTextField jtfGiaBan;
    private javax.swing.JTextField jtfHinhBia;
    private javax.swing.JTextField jtfHinhChiTiet;
    private javax.swing.JTextField jtfMaSach;
    private javax.swing.JTextField jtfNgayNhap;
    private javax.swing.JTextField jtfSoLuong;
    private javax.swing.JTextField jtfTacGia;
    private javax.swing.JTextField jtfTenSach;
    // End of variables declaration//GEN-END:variables
}
